<?php

namespace App\Http\Controllers\Api;

use App\User;
use Dingo\Api\Routing\Helpers;
use Illuminate\Http\Request;
//use Illuminate\Routing\Controller;
use JWTAuth;
use App\Http\Controllers\Controller;
use Tymon\JWTAuth\Exceptions\JWTException;
use Tymon\JWTAuth\Exceptions\TokenExpiredException;
use Tymon\JWTAuth\Exceptions\TokenInvalidException;

class BaseController extends Controller
{
    //
    use Helpers;

    public function __construct()
    {
        header('Access-Control-Allow-Origin:*');
    }

    public function is_login($request){

        if(!$token = $request->token){
            throw new JWTException('token缺失');
        }

        if (!$user = JWTAuth::toUser($request->token)) {
            throw new JWTException('token缺失或已失效');
        }
        return success($user,'操作成功');
    }


    public function get_token(){
        $user = User::first();
        return $this->response()->created('get token',JWTAuth::fromUser($user));
    }

}
